from collections import defaultdict


def open_picuture(profile_path):
    try:
        return open(profile_path, "a+b")
    except OSError:
        print("打开文件失败")
        raise


class Pictures(dict):
    def __missing__(self, key):
        value = open_picuture(key)
        self[key] = value
        return value


pictures = Pictures()

path = "profile_1234.png"

handle = pictures[path]
handle.seek(0)
image_data = handle.read()
